﻿using System;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;

namespace Babylon.Animations.UnitTests
{
    [TestClass]
    public class MatrixAnimationControllerTests
    {
        static Matrix _mFrom = new Matrix(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        static Matrix _mTo = new Matrix(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        [TestMethod]
        public void UpdateWhileRunningMustLerpMatrix()
        {
            var testee = new MatrixAnimation();
            testee.BaseValue = _mFrom;
            testee.ToValue = _mTo;
            testee.Duration = 1;

            Assert.AreEqual(_mFrom, testee.CurrentValue);
            testee.Start(1);
            Assert.AreEqual(AnimationState.Running, testee.AnimationState);
            Assert.AreEqual(_mFrom, testee.CurrentValue);
            testee.Update(1.5f);
            Assert.AreEqual(AnimationState.Running, testee.AnimationState);
            Assert.AreEqual(Matrix.Lerp(_mFrom, _mTo, 0.5f), testee.CurrentValue);
            testee.Update(2);
            Assert.AreEqual(_mTo, testee.CurrentValue);

            Assert.AreEqual(AnimationState.Paused, testee.AnimationState);
        }

        [TestMethod] 
        public void UpdateShouldUseEasingFunction()
        {
            var testee = new MatrixAnimation();
            testee.BaseValue = _mFrom;
            testee.ToValue = _mTo;
            testee.Duration = 1;

            bool easingUsed = false;
            EasingFunction easingFunc = x => {
                easingUsed = true;
                return 0;
            };

            testee.EasingFunction = easingFunc;

            testee.Start(1);
            Assert.IsTrue(easingUsed);
            easingUsed = false;
            Assert.AreEqual(_mFrom, testee.CurrentValue);
            testee.Update(1.5f);
            Assert.IsTrue(easingUsed);
            easingUsed = false;
            Assert.AreEqual(_mFrom, testee.CurrentValue);
            testee.Update(2);
            Assert.IsTrue(easingUsed);
            Assert.AreEqual(_mFrom, testee.CurrentValue);
        }
    }
}